//
//  HomeRecmmendSectionOneCell.m
//  copyrightTrading
//
//  Created by edz on 2020/10/9.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "HomeRecmmendSectionOneCell.h"
#import "LVCycleScrollView.h"

@interface HomeRecmmendSectionOneCell ()<LVCycleScrollViewDelegate>
@property (nonatomic, strong) LVCycleScrollView *cycleScrollView;
@end

@implementation HomeRecmmendSectionOneCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = RGB_VALUE(0xF5F5F5);
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UIView *bgView = [UIView new];
    bgView.backgroundColor = RGB_VALUE(0xFFFFFF);
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.bottom.offset(-4);
    }];
}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    if (!self.cycleScrollView && dataArray.count) {
        NSMutableArray *img = [NSMutableArray array];
        NSMutableArray *title = [NSMutableArray array];
        for (int i = 0; i < dataArray.count; i ++) {
            [img addObject:dataArray[i][@"thumb"]];  // @"http://image.uat.jinshisong.com.cn//img/upload/2008/12/c346bdec7807.jpg"];//
            [title addObject:dataArray[i][@"title"]];
        }
        self.cycleScrollView = [[LVCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, 210) itemSize:CGSizeMake(kDeviceWidth - 35, 190) scrollType:LVImageScroll scrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.cycleScrollView.infiniteLoop = YES;
        self.cycleScrollView.showPageControl = NO;
        self.cycleScrollView.imagesArray = [img copy];
        self.cycleScrollView.titlesArray = [title copy];
        self.cycleScrollView.space = 7;
        self.cycleScrollView.delegate = self;
        self.cycleScrollView.cellCornerRadius = 6;
        self.cycleScrollView.visibleCount = img.count;
        if (img.count < 2) {
            self.cycleScrollView.autoScroll = NO;
        }
        [self addSubview:self.cycleScrollView];
    }
}

/// 点击回调,文字滚动样式1和4回调都是0
- (void)cycleScrollView:(LVCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"=-=-=-=%ld",(long)index);
    if ([self.delegate respondsToSelector:@selector(tapSectionOneCellWithData:)]) {
        [self.delegate tapSectionOneCellWithData:self.dataArray[index]];
    }
}
@end
